import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class  UserManagementSystem {
private static UserManagementSystem instance = new UserManagementSystem();
private Map<String, User> users = new HashMap<>();

private UserManagementSystem() {}

public static UserManagementSystem getInstance() {
    return instance;
}

public boolean registerUser(User user) {
    if (users.containsKey(user.getUsername())) {
        System.out.println("注册失败：用户名已存在");
        return false;
    }
    users.put(user.getUsername(), user);
    System.out.println("注册成功：" + user.getUsername() + " (" + user.getRole() + ")");
    return true;
}

public User login(String username, String password) {
    User user = users.get(username);
    if (user == null) {
        System.out.println("登录失败：用户不存在");
        return null;
    }
    if (!user.getPassword().equals(password)) {
        System.out.println("登录失败：密码错误");
        return null;
    }
    System.out.println("登录成功：" + user.getUsername() + " (" + user.getRole() + ")");
    return user;
}

public List<User> getAllUsers() {
    return new ArrayList<>(users.values());
}

public User findUserByUsername(String username) {
    return users.get(username);
}
}
